package net.noday.demo.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.noday.demo.domain.User;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/user")
public class UserController2 {

	@RequestMapping(value="/login/{user}", method=RequestMethod.GET)
	public ModelAndView myMethod(HttpServletRequest request, 
			HttpServletResponse response, 
			@PathVariable("user")String user, ModelMap model) {
		model.put("loginUser", user);
		return new ModelAndView("/login/hello", model);
	}
	
	@RequestMapping(value="/welcome", method=RequestMethod.GET)
	public String registPost() {
		return "/welcome";
	}
	
	@RequestMapping(value="/login", method=RequestMethod.POST)//ͨ��form�ύ
	public String test(HttpServletRequest request, HttpServletResponse response, 
			User user) {
		if (user.getEmail().equals("a") && user.getPassword().equals("b")) {
			request.setAttribute("user", user);
			return "user/list";
		} else {
			return "user/loginerr";
		}
	}
}
